import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loxen/api/api.dart';
import 'package:loxen/dialog/toast.dart';
import 'package:loxen/utils/string_res.dart';
import 'package:loxen/widget/my_subassembly.dart';
import 'package:loxen/dialog/toast.dart';

class FeedbackWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var _textController = TextEditingController();
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size(double.infinity, 95.h),
        child: Container(
          color: Theme.of(context).backgroundColor,
          child: SafeArea(
            child: Column(
              children: <Widget>[
                Row(
                  children: <Widget>[
                    MySubassembly.getBackIcon(context,
                        color: Theme.of(context).textTheme.subtitle2.color),
                    Expanded(
                      child: Center(
                        child: Text(
                          StringResources.yi_jian_fan_kui,
                          style: TextStyle(
                              fontSize: 32.sp,
                              fontWeight: FontWeight.w500,
                              color:
                                  Theme.of(context).textTheme.subtitle2.color),
                        ),
                      ),
                    ),
                    MySubassembly.getSearchIcon(null, text: Text('')),
                  ],
                )
              ],
            ),
          ),
        ),
      ),
      resizeToAvoidBottomPadding: false,
      body: Container(
        decoration: BoxDecoration(
          border: Border(top: BorderSide(
              width: 1.h,
              color: Color(0xFFEBECF1)
          )),
          color: Theme.of(context).backgroundColor,
        ),
        child: Stack(
          children: <Widget>[
            Container(
              margin: EdgeInsets.fromLTRB(48, 60, 48, 0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    'LOXEN用户反馈',
                    style: TextStyle(
                        color: Color(0xFF000000),
                        fontSize: 48.sp,
                        fontWeight: FontWeight.bold),
                  ),
                  Text(
                    '期待您的意见和问题反馈',
                    style: TextStyle(
                        color: Color(0xFF82868E),
                        fontSize: 28.sp,
                        fontWeight: FontWeight.w500),
                  ),
                  Container(
                    width: 560.w,
                    height: 360.h,
                    margin: EdgeInsets.only(top: 40),
                    color: Color(0xFFF2F2F2),
                    child: TextField(
                      keyboardType: TextInputType.multiline,
                      maxLines: 10,
                      //不限制行数
                      controller: _textController,
                      decoration: InputDecoration(
                        contentPadding: EdgeInsets.only(left: 20.w, top: 30.h),
                        hintText: '请留下您宝贵的意见',
                        border: InputBorder.none,
                        isDense: true,
                      ),
                      style: TextStyle(color: Colors.black45, fontSize: 28.sp),
                    ),
                  ),
                ],
              ),
            ),
            Positioned(
              bottom: 80,
              left: 48,
              child: Builder(
                  builder: (context) => Container(
                        width: MediaQuery.of(context).size.width - 96,
                        child: FlatButton(
                          onPressed: () async {
                            String text = _textController.text;
                            if (text.length == 0 || text.isEmpty) {
                              Toast.show('意见内容不能为空', context);
                            } else {
                              ApiService.feedback(text).listen((event) {
                                Toast.show('反馈成功', context);
                                Navigator.of(context).pop();
                              }, onError: (error) {
                                Toast.show('网络异常', context);
                              });
                              _textController.text = '';
                            }
                          },
                          textColor: Colors.white,
                          color: Color(0xFF0CABCB),
                          disabledTextColor: Color(0xFFF7F8F8),
                          disabledColor: Color(0xFF999999),
                          child: Container(
                            height: 48,
                            alignment: Alignment.center,
                            child: Text(
                              '提交',
                              style: TextStyle(fontSize: 30.sp),
                            ),
                          ),
                        ),
                      )),
            ),
          ],
        ),
      ),
    );
  }
}
